package com.twu.biblioteca;

import java.util.ArrayList;


public class Shelf {
    ArrayList<Resource> resources = new ArrayList<Resource>();

    public int count() {
        return resources.size();
    }

    public boolean add(Resource resource) {
        return resources.add(resource);
    }


    public boolean remove(Resource resource) {
        return resources.remove(resource);
    }

    public String display() {
        String display = "";
        if(resources.size() > 0){
            for (Resource resource:resources){
                display += resource.display() + Messages.NEW_LINE;
            }

            return display;
        }   else{
            return Messages.NO_RESOURCES_FOUND;
        }

    }


    public Resource getByTitle(String title) {
        if(resources.size() > 0){
            for(Resource resource:resources){
               if(resource.titleMatches(title)){
                   return resource;
               }
            }
        }
        return null;
    }

    public final Shelf createMovieShelf() {
        Shelf movieShelf = new Shelf();
            movieShelf.add(new Movie("The last air bender", "2010", "M. Night Shyamalan", "10/10"));
            movieShelf.add(new Movie("The Gladiator", "2000", "Ridley Scott", "10/10"));
            movieShelf.add(new Movie("The Italian Job", "2003", "F. Gary Gray", "10/10"));
            movieShelf.add(new Movie("Enter The Dragon", "1973", "Robert Clouse", "10/10"));
            movieShelf.add(new Movie("Way of the dragon", "1974", "Bruce Lee", "10/10"));
            movieShelf.add(new Movie("The Legend Drunken Master", "1978", "Yuen Woo-ping", "10/10"));
            movieShelf.add(new Movie("The Bourne Legacy", "2012", "Tony Gilroy", "10/10"));
            movieShelf.add(new Movie("Mission: Impossible – Ghost Protocol", "2012", "Brad Bird", "10/10"));
            movieShelf.add(new Movie("Killer Elite", "2012", "Gary McKendry", "10/10"));
            movieShelf.add(new Movie("Tears of the Sun", "2003", "Antoine Fuqua", "6/10"));
            movieShelf.add(new Movie("The Expendables I", "2010", "Sylvester Stallone", "10/10"));
            movieShelf.add(new Movie("The Expendables II", "2012", "Simon West", "10/10"));
            movieShelf.add(new Movie("The Man with the Iron Fists", "2012", "RZA", "10/10"));

        return movieShelf;
    }

    public final Shelf createBookShelf() {
        Shelf bookShelf = new Shelf();
        bookShelf.add(new Book("Refactoring", "Martin Fowler", "0-20148567-2"));
        bookShelf.add(new Book("NoSQL Distilled", "Martin Fowler", "978-0-321-82662-6"));
        bookShelf.add(new Book("The productive programmer", "Neal Ford", "978-0-596-51978-0"));
        return bookShelf;
    }
}
